<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/4
 * Time: 11:09
 */
//针对于用户的数据的封装，继承，多态
//面向对线的编程方法
class UserDb
{

    function selectUser($user)
    {
        $sql = "select * from user where user='$user'";
        $dbConn = new DbCon();
        return $dbConn->query($sql);
    }
    function selectUserAdmin($user)
    {
        $sql = "select * from user where admin='$user'";
        $dbConn = new DbCon();
        return $dbConn->query($sql);
    }
    function queryAdUpadte($user){
        $sql = "select * from user where user='$user'and user not in('$user')";
        $dbConn = new DbCon();
        return $dbConn->query($sql);
    }
    function adminClass($user)
    {
        $sql = "select * from admin where user='$user'";
        $dbConn = new DbCon();
        return $dbConn->query($sql);
    }
    //查询注册的用户
    function queryUser($user){
        $sql = "select * from user where user='$user'";
        $dbConn = new DbCon();
        return $dbConn->query($sql);

    }
    //查询注册的用户
    function queryUserId($id){
        $sql = "select * from user where id='$id'";
        $dbConn = new DbCon();
        return $dbConn->query($sql);

    }
    //查找用户信息（同一个小组）
    function selectUserClass($class)
    {
        $sql = "select * from user where class='$class'";
        $dbConn = new DbCon();
        return $dbConn->query($sql);
    }
    function selectPass($user,$password)
    {
        $sql = "select * from user where user='$user' and pass='$password'";
        $dbConn = new DbCon();
        return $dbConn->query($sql);
    }
    function selectUserA($group)
    {
        $sql = "select * from user where class='$group'";
        $dbConn = new DbCon();
        return $dbConn->query($sql);
    }
    function selectUserId($id)
    {
        $sql = "select * from user where id='$id'";
        $dbConn = new DbCon();
        return $dbConn->query($sql);
    }
    //管理员的添加信息
    public function add_user($userA, $class,$pass,$user,$addtime)
    {
        $sql = "insert into user(user,class,pass,admin,addtime) values('$userA','$class','$pass','$user','$addtime')";
        $dbConn = new DbCon();
        return $dbConn->add($sql);

    }
//管理员删除用户
    function del_user($id){
        $sql="delete from user where id='$id'";
        $dbCon=new DbCon();
        return $dbCon->delete($sql);

    }
    //管理员删除用户
    function delNewUser($id){
        $sql="delete from student where id='$id'";
        $dbCon=new DbCon();
        return $dbCon->delete($sql);

    }
    //管理员对用户信息的修改
    function updateUser($id,$user,$pass,$class){
        $sql="update user set user='$user',pass='$pass',class='$class' where id='$id'";
        $dbCon=new DbCon();
        return $dbCon->modify($sql);
    }
    function updateUserA($id,$user,$class,$url,$tel,$email,$addtime){

        $sql="update user set user='$user',class='$class',img='$url',tel='$tel',email='$email',addtime='$addtime' where id='$id'";
        $dbCon=new DbCon();
        return $dbCon->modify($sql);
    }
    function updateUserPass($id,$user,$pass,$class,$url,$tel,$email,$addtime){

        $sql="update user set user='$user',pass='$pass',class='$class',img='$url',tel='$tel',email='$email',addtime='$addtime' where id='$id'";
        $dbCon=new DbCon();
        return $dbCon->modify($sql);
    }
    //用户接受任务
    function acceptTask($id,$task,$user,$accept){
        $sql="update task set task_a='$task',user_a='$user',accept_time='$accept' where id='$id'";
        $dbCon=new DbCon();
        return $dbCon->modify($sql);
    }

    //用户查询自己小组的任务
    function selectTaskUser($user){
        $sql = "select * from task where user_a='$user' order by id desc";
        $dbConn = new DbCon();
        return $dbConn->query($sql);

    }
    //用户查询自己小组的任务
    function selectTaskId($id){
        $sql = "select * from task where id='$id'";
        $dbConn = new DbCon();
        return $dbConn->query($sql);

    }
    function selectSelfTask($id){
        $sql = "select * from user_task where id='$id'";
        $dbConn = new DbCon();
        return $dbConn->query($sql);
    }
    //user用户查询自己的任务
    function quertTaskUser($user){
        $sql="select * from user_task where user='$user'";
        $dbConn=new DbCon();
        return $dbConn->query($sql);

    }
    //user用户写入自己任务打到user_task中
    function userAddTask($user,$content,$create_time,$over_time,$bei){
        $sql="insert into user_task(user,content,create_time,over_time,bei)values('$user','$content','$create_time','$over_time','$bei')";
        $dbConn=new DbCon();
        return $dbConn->add($sql);

    }
    //用户完成小组任务
    function updateTime($id,$addtime){
        $sql="update task set complete='$addtime' where id='$id'";
        $dbCon=new DbCon();
        return $dbCon->modify($sql);
    }

    //用户删除任务
    function delTask($id){
        $sql="delete from user_task where id='$id'";
        $dbConn=new DbCon();
        return $dbConn->delete($sql);

    }
    //用户完成自己的任务
    function updateTimeSelf($id,$addtime){
        $sql="update user_task set complete='$addtime' where id='$id'";
        $dbCon=new DbCon();
        return $dbCon->modify($sql);
    }
    //用户上传文件
    function updateUpload($id,$file,$addtime){
        $sql="update task set file='$file', file_time='$addtime' where id='$id'";
        $dbCon=new DbCon();
        return $dbCon->modify($sql);
    }
    function selectClassName($class){
        $sql="select * from admin where className='$class' ";
        $dbCon=new DbCon();
        return $dbCon->query($sql);
    }
    function selectAdminCode($code){
        $sql="select * from admin where code='$code' ";
        $dbCon=new DbCon();
        return $dbCon->query($sql);
    }
    function addUser($user,$pass,$class,$code,$email,$admin,$addtime){
        $sql="insert into user(user,pass,class,code,email,admin,addtime)values('$user','$pass','$class','$code','$email','$admin','$addtime')";
        $dbCon=new DbCon();
        return $dbCon->add($sql);
    }
//群发邮件查询用户的邮箱
    function selectNoticeUser($user)
    {
        $sql = "select * from user where admin='$user'";
        $dbConn = new DbCon();
        return $dbConn->query($sql);
    }
    function selectStudent($userA){

        $sql = "select * from student where user='$userA'";
        $dbConn = new DbCon();
        return $dbConn->query($sql);

    }
    function add_student($userA, $sex,$tel,$email,$major,$hobdy,$content,$addtime){

        $sql="insert into student(user,sex,tel,email,major,hobdy,content,addtime) values('$userA','$sex','$tel','$email','$major','$hobdy','$content','$addtime')";
        $dbCon=new DbCon();
        return $dbCon->add($sql);

    }

}